package com.xx.happychatboot.serve.user.controller;


import com.xx.happychatboot.base.vo.response.ResponseDate;
import com.xx.happychatboot.serve.user.domain.entity.UserApply;
import com.xx.happychatboot.serve.user.service.IUserApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.Objects;

/**
 * <p>
 * 用户申请表 前端控制器
 * </p>
 *
 * @author xiaoXuan
 * @since 2025-01-02
 */
@Controller
@RequestMapping("/userApply")
public class UserApplyController {
    @Autowired
    private IUserApplyService userApplyService;

    /**
     * 添加好友申请信息
     * @param userApply
     * @return
     */
    @PostMapping("/applyFriend")
    @ResponseBody
    public ResponseDate applyFriend(@RequestBody UserApply userApply) {
        return userApplyService.applyFriend(userApply);
    }

    /**
     * 获取好友申请列表
     * @param userId
     * @return
     */
    @GetMapping("/getApplyList/{userId}")
    @ResponseBody
    private ResponseDate getUserInfo(@PathVariable("userId") Long userId) {
        if (Objects.isNull(userId)) {
            return ResponseDate.fail("用户ID不能为空");
        }
        return ResponseDate.success(userApplyService.getApplyList(userId));
    }

    /**
     * 获取好友申请数
     * @param userId
     * @return
     */
    @GetMapping("/getApplyListCount/{userId}")
    @ResponseBody
    private ResponseDate getApplyListCount(@PathVariable("userId") Long userId) {
        return userApplyService.getApplyListCount(userId);
    }

    /**
     * 获取好友申请详细信息
     * @param userId
     * @return
     */
    @GetMapping("/getNewFriendList/{userId}")
    @ResponseBody
    private ResponseDate getNewFriendList(@PathVariable("userId") Long userId) {
        return ResponseDate.success(userApplyService.getNewFriendList(userId));
    }

    /**
     * 同意添加好友
     * @param userApply
     * @return
     */
    @PostMapping("/agreeAddFried")
    @ResponseBody
    public ResponseDate agreeAddFried(@RequestBody UserApply userApply) {
        return userApplyService.agreeAddFried(userApply);
    }
}

